home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12524 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: array[index]
  5. Date: 1 Apr 1996 06:47:11 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4joq9fINNed0@keats.ugrad.cs.ubc.ca>
  8. References: <4jiies$3bh@fnord.dfw.net>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4jiies$3bh@fnord.dfw.net>,
  12. Azazel Diabolus            (aka Fetelgeuse) <ftlgeuse@dfw.dfw.net> wrote:
  13.  >On my platform's assembly language a[n] is the same as n[a]; is this also 
  14.  >valid in C? Does array[index] give the same address as index[array]? I 
  15.  >will try this after I post it but I would like to know if this is 
  16.  >something defined by the ANSI standard. Thanks,
  17.  
  18. Funny you should ask, but it is so defined. I've never thought of it as a
  19. similarity to assembly language, but come to think of it, it does somewhat
  20. reinforce the common stereotype of C as a ``portable assembler''. Heh.
  21.  
  22. The reason it works is because the expression E1[E2] is equivalent to
  23. *((E1) + (E2)) by definition. The latter is commutative, so it doesn't matter
  24. whether E1 is the pointer expression and E2 the integral expression or vice
  25. versa. Thus it follows that E1[E2] also commutes.
  26. -- 
  27.  
  28.